<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit - Firmware API: Fast Timer</title>
<link href="mt_doxygen.css" rel="stylesheet" type="text/css" />
<link href="../resources/mt_doxytabs.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.header {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12pt;
	color: #222222;
}
-->
</style>
</head>

<body>
<table width="800" border="0">
    <tr>
      <td colspan="3">
        <form method="get" action="http://www.google.com/search">
          <div align="right">
            <input type="text"   name="q" size="25"
              maxlength="255" value="" />
            <input type="submit" value="Search" />
            <input type="hidden" name="sitesearch" value="makingthings.com/ref/firmware/html" />
          </div>
        </form>
       </td>
    </tr>
    <tr>
      <td><div align="center"><a href="http://www.makingthings.com">
				<img src="../resources/logo_brown_medium.png" alt="MakingThings"
									width="200" height="78" border="0" align="middle" longdesc="http://www.makingthings.com" /></a></div></td>
				<td><div align="center" class="header">
      		Make Controller Kit <br />
          Firmware API
      </div></td>
      <td><div align="center"><a href="http://www.makezine.com">
					<img src="../resources/make_logo.png" alt="MAKE Zine" 
										width="164" height="73" border="0" align="middle" longdesc="http://www.makezine.com" /></a></div></td>
    </tr>
</table>
</body>
</html>
<!-- Generated by Doxygen 1.5.4 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>Fast Timer<br>
<small>
[<a class="el" href="group___controller.html">Controller</a>]</small>
</h1>The FastTimer subsystem provides a high resolution timer in a microsecond context.  
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___fast_timer.html#g2c67c0fd2281b1eb3fd936eb37a7410e">FastTimer_SetActive</a> (bool active)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Controls the active state of the Fast Timer system.  <a href="#g2c67c0fd2281b1eb3fd936eb37a7410e"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___fast_timer.html#gf96a05dd9e1d57cbccce64565c969331">FastTimer_GetActive</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns whether the timer subsystem is active or not.  <a href="#gf96a05dd9e1d57cbccce64565c969331"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___fast_timer.html#g7fbd4c8b28335479fb66673a64159336">FastTimer_InitializeEntry</a> (FastTimerEntry *fastTimerEntry, void(*timerCallback)(int id), int id, int timeUs, bool repeat)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initializes a fast timer entry structure.  <a href="#g7fbd4c8b28335479fb66673a64159336"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___fast_timer.html#g2db79bbca7af495bf61ebad8abdeb806">FastTimer_SetTime</a> (FastTimerEntry *fastTimerEntry, int timeUs)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Change the requeted time of an entry.  <a href="#g2db79bbca7af495bf61ebad8abdeb806"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___fast_timer.html#gf20a5ff8dabaf78362d54e806df9a900">FastTimer_Set</a> (FastTimerEntry *fastTimerEntry)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets the requested entry to run.  <a href="#gf20a5ff8dabaf78362d54e806df9a900"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___fast_timer.html#gd722adc5f81948844c6e853e40910300">FastTimer_Cancel</a> (FastTimerEntry *fastTimerEntry)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Stops the requested fast timer entry from running.  <a href="#gd722adc5f81948844c6e853e40910300"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The FastTimer subsystem provides a high resolution timer in a microsecond context. 
<p>
If you don't need such high resolution timing, check the <a class="el" href="group___timer.html">Timer</a><p>
The Fast Timer subsystem is based on a collection of <b>FastTimerEntries</b>. To start a new timer, create a new <b>FastTimerEntry</b> structure, initialize it with <a class="el" href="group___fast_timer.html#g7fbd4c8b28335479fb66673a64159336" title="Initializes a fast timer entry structure.">FastTimer_InitializeEntry( )</a>, and start it with <a class="el" href="group___fast_timer.html#gf20a5ff8dabaf78362d54e806df9a900" title="Sets the requested entry to run.">FastTimer_Set( )</a>.<p>
There are currently one main limitation to the Fast Timer system:<ul>
<li>In your callback function, you must not sleep or make any FreeRTOS-related calls.</li></ul>
<p>
<dl compact><dt><b><a class="el" href="todo.html#_todo000002">Todo:</a></b></dt><dd>Allow the fast timer callbacks to cooperate with the <a class="el" href="group___r_t_o_s.html">RTOS</a> </dd></dl>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="gd722adc5f81948844c6e853e40910300"></a><!-- doxytag: member="fasttimer.c::FastTimer_Cancel" ref="gd722adc5f81948844c6e853e40910300" args="(FastTimerEntry *fastTimerEntry)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int FastTimer_Cancel           </td>
          <td>(</td>
          <td class="paramtype">FastTimerEntry *&nbsp;</td>
          <td class="paramname"> <em>fastTimerEntry</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Stops the requested fast timer entry from running. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>fastTimerEntry</em>&nbsp;</td><td>pointer to the FastTimerEntry to be cancelled. </td></tr>
  </table>
</dl>

<p>Definition at line <a class="el" href="fasttimer_8c-source.html#l00229">229</a> of file <a class="el" href="fasttimer_8c-source.html">fasttimer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="gf96a05dd9e1d57cbccce64565c969331"></a><!-- doxytag: member="fasttimer.c::FastTimer_GetActive" ref="gf96a05dd9e1d57cbccce64565c969331" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int FastTimer_GetActive           </td>
          <td>(</td>
          <td class="paramtype">void&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns whether the timer subsystem is active or not. 
<p>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>active. </dd></dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___fast_timer.html#gf20a5ff8dabaf78362d54e806df9a900" title="Sets the requested entry to run.">FastTimer_Set</a>, <a class="el" href="group___fast_timer.html#gd722adc5f81948844c6e853e40910300" title="Stops the requested fast timer entry from running.">FastTimer_Cancel</a> </dd></dl>

<p>Definition at line <a class="el" href="fasttimer_8c-source.html#l00094">94</a> of file <a class="el" href="fasttimer_8c-source.html">fasttimer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g7fbd4c8b28335479fb66673a64159336"></a><!-- doxytag: member="fasttimer.c::FastTimer_InitializeEntry" ref="g7fbd4c8b28335479fb66673a64159336" args="(FastTimerEntry *fastTimerEntry, void(*timerCallback)(int id), int id, int timeUs, bool repeat)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void FastTimer_InitializeEntry           </td>
          <td>(</td>
          <td class="paramtype">FastTimerEntry *&nbsp;</td>
          <td class="paramname"> <em>fastTimerEntry</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void(*)(int id)&nbsp;</td>
          <td class="paramname"> <em>timerCallback</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>timeUs</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&nbsp;</td>
          <td class="paramname"> <em>repeat</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Initializes a fast timer entry structure. 
<p>
The event is signified by a callback to the function provided, after the interval specified. The specified ID is passed back to the function to permit one function to work for many events. Pass repeat = true to make the event continue to create callbacks until it is canceled. Note that the timer entry structure needs to be created and managed by the caller. The longest period for a fast timer entry is 2^32 / 1000000 = 4294s. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>fastTimerEntry</em>&nbsp;</td><td>pointer to the FastTimerEntry to be intialized. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>timerCallback</em>&nbsp;</td><td>pointer to the callback function. The function must be of the form <div class="fragment"><pre class="fragment">void callback( int id ) </pre></div> </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>id</em>&nbsp;</td><td>An integer specifying the ID the callback function is to be provided with. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>timeUs</em>&nbsp;</td><td>The time in microseconds desired for the callback. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>repeat</em>&nbsp;</td><td>Set whether the timer repeats or is a one-time event. </td></tr>
  </table>
</dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___fast_timer.html#gd722adc5f81948844c6e853e40910300" title="Stops the requested fast timer entry from running.">FastTimer_Cancel</a></dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  TimerEntry myTimer; <span class="comment">// our TimerEntry</span>
  <a class="code" href="group___fast_timer.html#g7fbd4c8b28335479fb66673a64159336" title="Initializes a fast timer entry structure.">FastTimer_InitializeEntry</a>( &amp;myTimer, myCallback, 0, 250, <span class="keyword">true</span> );
  <a class="code" href="group___fast_timer.html#gf20a5ff8dabaf78362d54e806df9a900" title="Sets the requested entry to run.">FastTimer_Set</a>( &amp;myTimer ); <span class="comment">// start our timer</span>

  <span class="keywordtype">void</span> myCallback( <span class="keywordtype">int</span> <span class="keywordtype">id</span> ) <span class="comment">// our code that will get called by the timer every 250 microseconds.</span>
  {
    <span class="comment">// do something here</span>
  }
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="fasttimer_8c-source.html#l00126">126</a> of file <a class="el" href="fasttimer_8c-source.html">fasttimer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="gf20a5ff8dabaf78362d54e806df9a900"></a><!-- doxytag: member="fasttimer.c::FastTimer_Set" ref="gf20a5ff8dabaf78362d54e806df9a900" args="(FastTimerEntry *fastTimerEntry)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int FastTimer_Set           </td>
          <td>(</td>
          <td class="paramtype">FastTimerEntry *&nbsp;</td>
          <td class="paramname"> <em>fastTimerEntry</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Sets the requested entry to run. 
<p>
This routine adds the entry to the running queue and then decides if it needs to start the timer (if it's not running) or alter the timer's clock for a shorter period. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>fastTimerEntry</em>&nbsp;</td><td>A pointer to the FastTimerEntry to be run. </td></tr>
  </table>
</dl>

<p>Definition at line <a class="el" href="fasttimer_8c-source.html#l00160">160</a> of file <a class="el" href="fasttimer_8c-source.html">fasttimer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g2c67c0fd2281b1eb3fd936eb37a7410e"></a><!-- doxytag: member="fasttimer.c::FastTimer_SetActive" ref="g2c67c0fd2281b1eb3fd936eb37a7410e" args="(bool active)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int FastTimer_SetActive           </td>
          <td>(</td>
          <td class="paramtype">bool&nbsp;</td>
          <td class="paramname"> <em>active</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Controls the active state of the Fast Timer system. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>active</em>&nbsp;</td><td>whether the FastTimer subsystem is active or not </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Zero on success. </dd></dl>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="group___fast_timer.html#gf20a5ff8dabaf78362d54e806df9a900" title="Sets the requested entry to run.">FastTimer_Set</a>, <a class="el" href="group___fast_timer.html#gd722adc5f81948844c6e853e40910300" title="Stops the requested fast timer entry from running.">FastTimer_Cancel</a> </dd></dl>

<p>Definition at line <a class="el" href="fasttimer_8c-source.html#l00065">65</a> of file <a class="el" href="fasttimer_8c-source.html">fasttimer.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g2db79bbca7af495bf61ebad8abdeb806"></a><!-- doxytag: member="fasttimer.c::FastTimer_SetTime" ref="g2db79bbca7af495bf61ebad8abdeb806" args="(FastTimerEntry *fastTimerEntry, int timeUs)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void FastTimer_SetTime           </td>
          <td>(</td>
          <td class="paramtype">FastTimerEntry *&nbsp;</td>
          <td class="paramname"> <em>fastTimerEntry</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>timeUs</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Change the requeted time of an entry. 
<p>
This must only be called within a callback caused by the Entry specified or when the entry is not being used. If you need to change the duration of a timer, you need to cancel it and re-add it, or alter the time inside a callback. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>fastTimerEntry</em>&nbsp;</td><td>A pointer to the FastTimerEntry to be intialized. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>timeUs</em>&nbsp;</td><td>The time in microseconds desired for the callback. </td></tr>
  </table>
</dl>

<p>Definition at line <a class="el" href="fasttimer_8c-source.html#l00147">147</a> of file <a class="el" href="fasttimer_8c-source.html">fasttimer.c</a>.</p>

</div>
</div><p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit</title>
<style type="text/css">
<!--
.footer {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9pt;
	color: #999999;
}
-->
</style>
</head>

<body>
<hr size="1">
<div>
  <p class="footer">The Make Controller Kit is an open source project maintained by <a href="http://www.makingthings.com">MakingThings</a>.<br />
    MakingThings code is released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 license</a>.<br />
    Bug tracker, development wiki and status can be found at <a href="http://dev.makingthings.com">http://dev.makingthings.com</a>.<br />
		This document was last updated on 5 Dec 2007.
</p>
</div>
<!-- Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-769030-1";
urchinTracker();
</script>
</body>
</html>
